<?php
/*
* Description: Create all custom fields in custom post type  property.
* Version: 1.0
* Author: huuducvt
* Author URI: http://zonthemes.com/author/huuducvt
*/

add_action('admin_menu' ,'zontheme_features_metaboxes');
add_action('save_post', 'zontheme_features_metaboxes_save');


function zontheme_features_metaboxes() {
	add_meta_box('zonthemes_features_metabox', 'Features infomation', 'zontheme_features_metaboxes_view', 'features', 'advanced', 'high' );
}

function zontheme_features_metaboxes_view() {
	global $post;
	$zon_features_desc = get_post_meta($post->ID, 'zon_features_desc', true);
	$zon_features_link = get_post_meta($post->ID, 'zon_features_link', true); ?>
	<p>
		<label><?php _e('Insert description','zonthemes'); ?><label>
		<textarea style="width: 100%;" name="zon_features_desc" id="zon_features_desc" cols="80" rows="4"> <?php echo  $zon_features_desc; ?> </textarea>
	</p>
	<p>
		<label><?php _e('Insert link','zonthemes'); ?><label>
		<input class="zon-input" style="width: 100%; border-radius: -1px;" value="<?php echo  $zon_features_link; ?>" name="zon_features_link" id="zon_features_link" cols="80" rows="4" /> 
	</p>
	<?php
}

function zontheme_features_metaboxes_save($post_id) {
	global $post;
	if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; }
	if(isset($_POST['post_type'])) {
		if('page' == $_POST['post_type']) {
			if(!current_user_can('edit_page', $post_id)) { return $post_id; }
			if(!current_user_can('edit_post', $post_id)) { return $post_id; }
		}
	}
	if(isset($_POST['zon_features_desc'])) { update_post_meta($post_id, 'zon_features_desc', htmlspecialchars($_POST['zon_features_desc'])); } 
	if(isset($_POST['zon_features_link'])) { update_post_meta($post_id, 'zon_features_link', htmlspecialchars($_POST['zon_features_link'])); } 
}
